package siddur.traktask.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import siddur.traktask.entity.TaskInfo;
import siddur.traktask.facade.TaskFacade;

@Controller()
@RequestMapping("track")
public class TaskController {
	
	@Autowired
	TaskFacade taskFacade;

	@RequestMapping("{token}")
	public String trackTask(@PathVariable("token") String token, Model model){
		TaskInfo task = taskFacade.getTask(token);
		if(task != null){
			model.addAttribute("title", task.getName());
			model.addAttribute("taskId", task.getId());
			return "/trak.jsp";
		}
		return "/home.jsp";
	}
}
